package com.zide.system.controller.monitor;

import com.zide.common.annotation.Log;
import com.zide.common.core.domain.CommonResult;
import com.zide.common.core.domain.PageResult;
import com.zide.common.enums.BusinessType;
import com.zide.common.utils.poi.ExcelUtil;
import com.zide.common.core.domain.SysOperLog;
import com.zide.framework.web.domain.operlog.vo.SysOperLogSearchVO;
import com.zide.framework.web.service.ISysOperLogService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static com.zide.common.core.domain.CommonResult.getResult;
import static com.zide.common.core.domain.CommonResult.success;

/**
 * 操作日志记录
 *
 * @author zide
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController {
    @Autowired
    private ISysOperLogService operLogService;

    @GetMapping("/list")
    public CommonResult list(SysOperLogSearchVO searchVO) {

        PageResult<SysOperLog> list = operLogService.selectOperLogPage(searchVO);
        return success(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLog operLog) {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operIds}")
    public CommonResult remove(@PathVariable Long[] operIds) {
        return getResult(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public CommonResult clean() {
        operLogService.cleanOperLog();
        return success();
    }
}
